﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebChat.Models
{
    public class ChannelIndexViewModel
    {
        private IChannelRepository channelRep;
        private IUserRepository userRep;

        public Chatroom room { get; set; }              //Ett rom
        public List<Chatroom> rooms { get; set; }       //liste med aktive rom
        public List<Chatroom> yourRooms { get; set; }   //Liste med dine rom
        public List<Permitted_user> users { get; set; } //Rom der du har tilgang
        
        /// <summary>
        /// Metoden henter ut lister med rom og brukere som sendes til view
        /// </summary>
        /// <param name="userId">Brukers id</param>
        public ChannelIndexViewModel(Guid userId) 
        {
            userRep = new UserRepository();
            channelRep = new ChannelRepository();
            rooms = channelRep.showNotYourChatrooms(userId).ToList();
            yourRooms = channelRep.showYourChatrooms(userId).ToList();
            users = userRep.showYourPermittedRooms(userId).ToList();
         
        }

        /// <summary>
        /// Henter ut listene som skal sendes til view. 
        /// </summary>
        /// <param name="userId">Brukers ID</param>
        /// <param name="_userRep">UserRepository interface</param>
        /// <param name="_channelRep">Channel reposistory interface</param>
        public ChannelIndexViewModel(Guid userId, IUserRepository _userRep, IChannelRepository _channelRep)
        {
            userRep = _userRep;
            channelRep = _channelRep;
            rooms = channelRep.showNotYourChatrooms(userId).ToList();
            yourRooms = channelRep.showYourChatrooms(userId).ToList();
            users = userRep.showYourPermittedRooms(userId).ToList();

        }

        /// <summary>
        /// Returnerer aspnet_User kollonnen til input
        /// </summary>
        /// <param name="ownerId">Bruker ID</param>
        /// <returns></returns>
        public aspnet_User getOwner(Guid ownerId)
        {
            return userRep.showUser(ownerId);
        }
    }
}